package net.zjitc.servlet;

import jdk.nashorn.internal.codegen.types.BooleanType;
import net.zjitc.domain.product;
import net.zjitc.service.ProductService;
import net.zjitc.service.impl.ProductServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * @Author admin
 * @Date 2019/2/26 10:42
 */
@WebServlet(name = "addServlet",urlPatterns = "/add")
public class addServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        product product = new product();
        try {
            BeanUtils.populate(product,request.getParameterMap());
            ProductService service = new ProductServiceImpl();
            service.add(product);
        } catch (Exception e) {
            e.printStackTrace();
        }
        request.getRequestDispatcher("/findAll").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
